package com.admin.controller;


import com.admin.entity.Profession;
import com.admin.service.ProfessionService;
import com.admin.utils.Result;
import com.admin.vo.query.ProfessionQueryVo;
import com.baomidou.mybatisplus.core.metadata.IPage;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import org.springframework.web.bind.annotation.*;

import org.springframework.stereotype.Controller;

import javax.annotation.Resource;

/**
 * <p>
 * 专业表 前端控制器
 * </p>
 *
 * @author szy
 * @since 2023-03-02
 */
@RestController
@RequestMapping("/api/profession")
public class ProfessionController {
    @Resource
    private ProfessionService professionService;
    /*
    * 查询专业列表
    * */
    @GetMapping("/list")
    public Result list(ProfessionQueryVo professionQueryVo){
        //创建分页信息
        IPage<Profession> page = new Page<Profession>(professionQueryVo.getPageNo(),professionQueryVo.getPageSize());
        //调用分页查询方法
        professionService.getProfessionListByPage(page,professionQueryVo);
        return Result.ok(page);
    }

    @PostMapping("/add")
    public Result add(@RequestBody Profession profession){
        if (professionService.save(profession)){
            return Result.ok().message("专业添加成功");
        }else{
            return Result.error().message("添加专业失败");
        }
    }

    @PutMapping("/update")
    public Result update(@RequestBody Profession profession){
        if (professionService.updateById(profession)){
            return Result.ok().message("专业信息修改成功");
        }else
            return Result.error().message("专业信息修改失败");
    }

    @DeleteMapping("/delete/{id}")
    public Result delete(@PathVariable Integer id){
        if (professionService.removeById(id)){
            return Result.ok().message("专业删除成功");
        }else
            return Result.error().message("专业删除失败");
    }
}

